﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Baosight.Platform.Core;
using Baosight.Platform.Core.UI.Controls;
using Baosight.Platform.Core.ServiceModel;
using Baosight.Platform.Core.UI;
using Telerik.Windows.Controls;
using Microsoft.Practices.Unity;
using Baosight.ZNH.ZMCA.UI.Controls;
using System.Windows.Data;
using Baosight.Platform.Core.UI;
using Baosight.Platform.Core.ServiceModel;
using Microsoft.Practices.Unity;
using Baosight.ZNH.ZMCA.UI.Utils;
using Baosight.ZNH.ZMCA.UI.PopWindows;

namespace Baosight.ZNH.ZMCA.UI
{
    /// <summary>
    /// 生产问题查询页面
    /// </summary>
    public partial class ZMCA42 : EFView
    {
        public ZMCA42()
        {
            InitializeComponent();
        }

        public void OnQueryButtonClick(object sender, RoutedEventArgs e)
        {
            grid.Refresh();
        }

        private void AddColumnToBlock(EIBlock block, string colName, EIRow row, object colValue)
        {
            EIColumn column = new EIColumn();
            column.SetName(colName);
            row.Add(colName, colValue);
            block.AddColumn(column);
        }

        public void  OnShowButtonClick(object sender, RoutedEventArgs e)
        {
            if (grid.GetCheckedEIRows().Count != 1)
            {
                EFWindow.Alert("请选择一条记录进行查看");
                return; 
            }

            List<EIRow> list = grid.GetCheckedEIRows();
            EventHandler functions = null;
            ZMCASpecialCommon.ShowPopwindows(list[0]["fdProblemTypeId"].ToString(),
                list[0]["fdKeyId"].ToString(), functions, false);
        }

        public void OnIndicationButtonClick(object sender, RoutedEventArgs e)
        {
            if (grid.GetCheckedEIRows().Count != 1)
            {
                EFWindow.Alert("请选择一条记录对应的问题进行指示");
                return;
            }
            EFWindow window = new EFWindow();
            window.Header = "下达工作指示";
            ZMCA45 content = new ZMCA45();
            content.fdKeyId.Value = grid.CheckedEIRows[0]["fdKeyId"];
            content.fdProblemTypeId.Value = grid.CheckedEIRows[0]["fdProblemTypeId"];
            content.SetNew();
            content.ZMCA45_Loaded(sender, e);
            window.Content = content;
            window.ShowDialog();
        }
    }

    public class DateTimeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            DateTime nowTime = new DateTime();
            nowTime = System.DateTime.Now;
            string time = nowTime.ToString("yyyy-MM-dd");

            if (value.ToString() == time)
            {
                return "今日新增！";
            }
            else
            {
                return string.Empty;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }

    public class StateInstructionConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            switch (value.ToString())
            {
                case "新增": 
                    return "/Images/red.png";

                case "已查收": 
                    return "/Images/yellow.png";

                case "已反馈": 
                    return "/Images/green.png";
                default:
                    return "";
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
}
